package com.infoauto.opc.gateway.opc.model;

import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * 第三方配置接口的属性
 * */
@Getter
@Setter
public class WebInterfaceNode {
    /**
     * 第三方接口
     * */
    private WebInterface thirdInterface;

    /**
     * 关联OPC的节点集合
     * 一个第三方接口的属性，只对应OPC的一个数据节点
     * */
    //private Map<Integer,SubscribeNode> subscribeNodes;
    private SubscribeNode subscribeNode;

    /**
     * 关联MQTT的接口
     * 一个第三方接口，可以对应多个Mqtt的接口
     * */
    private Map<Integer,MqttInterfaceNode> mqttInterfaceNodes;

    /**
     * 属性的编号
     * */
    private int thirdNodeID;
    private String tagLabel;
    private String tagName;
    private String tagValue;
    private long lastTime;
    private int thirdInterfaceID;
    private int dataType;
    private int opcNodeID;

    public String toString() {
        this.lastTime = System.currentTimeMillis();

        StringBuilder ret = new StringBuilder();
        switch (this.dataType) {
            case 0:
                ret.append(new Boolean(this.tagValue));
                break;
            case 1:
                ret.append(new Short(this.tagValue));
                break;
            case 2:
                ret.append(new Integer(this.tagValue));
                break;
            case 3:
                ret.append(new Long(this.tagValue));
                break;
            case 4:
                ret.append(new Float(this.tagValue));
                break;
            case 5:
                ret.append(new Double(this.tagValue));
                break;
            case 6:
                ret.append("\"");
                ret.append(new Byte(this.tagValue));
                ret.append("\"");
                break;
            default:
                ret.append("\"");
                ret.append(this.tagValue);
                ret.append("\"");
                break;
        }

        return "\"" + tagName + "\":{\"Value\":" + ret.toString()  + ",\"Label\":\"" + this.tagLabel + "\",\"LastTime\":" + this.lastTime + "}";
    }
}
